package com.relytosoft.mizar.media.system.services.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.relytosoft.dubhe.common.core.base.page.PageQuery;
import com.relytosoft.mizar.media.system.api.entity.VidAlarmType;
import com.relytosoft.mizar.media.system.services.mapper.VidAlarmTypeMapper;
import com.relytosoft.mizar.media.system.services.service.VidAlarmTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 告警类型
 *
 * @Author SunLi
 * @Date: 2022/4/7 11:12
 * @Version 1.0
 */
@Service
public class VidAlarmTypeServiceImpl extends ServiceImpl<VidAlarmTypeMapper,VidAlarmType> implements VidAlarmTypeService {

    @Override
    public int updateVidAlarmTypeStatus(int id,int status){
        return baseMapper.update(null,new LambdaUpdateWrapper<VidAlarmType>().set(VidAlarmType::getStatus,status).eq(VidAlarmType::getId,id));
    }

    @Override
    public IPage<VidAlarmType> selectVidAlarmTypePageList(PageQuery pageQuery, VidAlarmType vidAlarmType) {
        return baseMapper.selectPageVidAlarmTypeList(pageQuery.build(),vidAlarmType);
    }

    @Override
    public boolean checkVidAlarmTypeNameUnique(VidAlarmType vidAlarmType){
        int id = ObjectUtil.isNull(vidAlarmType.getId()) ? -1 : vidAlarmType.getId();
        long count = count(new LambdaQueryWrapper<VidAlarmType>()
                .eq(VidAlarmType::getName, vidAlarmType.getName())
                .ne(VidAlarmType::getId, id));
        return count <= 0;
    }
}
